﻿using NUnit.Framework;
using System.Collections.Generic;
using AdventureWorks.Domain;
using System;
using System.Linq;
using AdventureWorks.DataAccess.Specifications;
namespace AdventureWorks.DataAccess.Test.Specifications
{
    [TestFixture]
    public class SpecialOfferSpecifiationTest
    {
        private IQueryable<SpecialOffer> query;
        [SetUp]
        public void Setup()
        {
            var d = new List<SpecialOffer>() {
                new SpecialOffer { Category = "Cat1", Type = "Type1", StartDate = new DateTime(2004, 3, 3)},
                new SpecialOffer { Category = "Cat2", Type = "Type1", StartDate = new DateTime(2004, 3, 3)},
                new SpecialOffer { Category = "Cat1", Type = "Type2", StartDate = new DateTime(2004, 3, 3)},
                new SpecialOffer { Category = "Cat2", Type = "Type2", StartDate = new DateTime(2004, 3, 3)}
            };
            query = d.AsQueryable();
        }


        [Test]
        public void Should_Query_By_Type()
        {
            var d = new SpecialOfferSpecification { Type = "Type1" };
            var c = d.IsSatisfiedBy(query).ToList();
            Assert.AreEqual(2, c.Count);
        }

        [Test]
        public void Should_Query_By_Category()
        {
            var d = new SpecialOfferSpecification { Category = "Cat1" };
            var c = d.IsSatisfiedBy(query).ToList();
            Assert.AreEqual(2, c.Count);
        }

        [Test]
        public void Should_Query_By_Category_And_Type()
        {
            var d = new SpecialOfferSpecification { Category = "Cat1" , Type = "Type2"};
            var c = d.IsSatisfiedBy(query).ToList();
            Assert.AreEqual(1, c.Count);
        }
    }
}
